﻿using UnityEngine;
using System.Collections;

public enum TextureType
{
    GrassSide,
    GrassTop,
    Dirt,
    Stone,
    Sand,
    IronOre,
    Bedrock
}

public static class TextureManager
{
    public const int TEXTURES_PER_SIDE = 16;
    public const float TEX_FACTOR = 1f / TEXTURES_PER_SIDE;

    public static Vector2 GetTexCoords(TextureType textype)
    {
        Point2 texCoord = new Point2((int)textype % TextureManager.TEXTURES_PER_SIDE, (TextureManager.TEXTURES_PER_SIDE - 1) - (int)textype / TextureManager.TEXTURES_PER_SIDE);
        return new Vector2(texCoord.x + 0, texCoord.y + 0);
    }

    /// <summary>
    /// Returns the top uv coordinates of a block
    /// </summary>
    /// <param name="block">The BlockID of the block</param>
    /// <returns>UV Coordinates for the top face</returns>
    public static Vector2 GetUV(byte block) 
    { 
            if (block == Block.Grass)
                return GetUV(TextureType.GrassSide);
            else if(block == Block.Stone)
                return GetUV(TextureType.Stone);
            else if(block == Block.Dirt)
                return GetUV(TextureType.Dirt);
            else if(block == Block.Sand)
                return GetUV(TextureType.Sand);
            else if(block == Block.IronOre)
                return GetUV(TextureType.IronOre);
            else if (block == Block.Bedrock)
                return GetUV(TextureType.Bedrock);
    		else
                return GetUV(TextureType.Stone);
}

    /// <summary>
    /// Returns the top uv coordinates of a block
    /// </summary>
    /// <param name="blockID">The BlockID of the block</param>
    /// <returns>UV Coordinates for the top face</returns>
    public static Vector2 GetUV(TextureType texType)
    {
        switch (texType)
        {
            default:
            case TextureType.GrassTop:
                return new Vector2(0, 15);
            case TextureType.GrassSide:
                return new Vector2(1, 15);
            case TextureType.Dirt:
                return new Vector2(2, 15);
            case TextureType.Stone:
                return new Vector2(3, 15);
            case TextureType.Sand:
                return new Vector2(4, 15);
            case TextureType.IronOre:
                return new Vector2(5, 15);
            case TextureType.Bedrock:
                return new Vector2(6, 15);
        }
    }


    ///// <summary>
    ///// Returns the top uv coordinates of a block
    ///// </summary>
    ///// <param name="blockID">The BlockID of the block</param>
    ///// <returns>UV Coordinates for the top face</returns>
    //public static Vector2[] GetBottomUV(BlockID blockID) { }
    ///// <summary>
    ///// Returns the top uv coordinates of a block
    ///// </summary>
    ///// <param name="blockID">The BlockID of the block</param>
    ///// <returns>UV Coordinates for the top face</returns>
    //public static Vector2[] GetLeftUV(BlockID blockID) { }
    ///// <summary>
    ///// Returns the top uv coordinates of a block
    ///// </summary>
    ///// <param name="blockID">The BlockID of the block</param>
    ///// <returns>UV Coordinates for the top face</returns>
    //public static Vector2[] GetRightUV(BlockID blockID) { }
    ///// <summary>
    ///// Returns the top uv coordinates of a block
    ///// </summary>
    ///// <param name="blockID">The BlockID of the block</param>
    ///// <returns>UV Coordinates for the top face</returns>
    //public static Vector2[] GetFrontUV(BlockID blockID) { }
    ///// <summary>
    ///// Returns the top uv coordinates of a block
    ///// </summary>
    ///// <param name="blockID">The BlockID of the block</param>
    ///// <returns>UV Coordinates for the top face</returns>
    //public static Vector2[] GetBackUV(BlockID blockID) { }

}
